'use strict';
import moment from 'moment'
export default class extends think.service.base {
    /**
     * init
     * @return {}         []
     */
    init(...args) {
        super.init(...args);
    }
    async pageByType(type,cur,limit){
        return  await this.model("news")
            .page([cur,limit])
            .where({cate:type})
            .countSelect();
    }
    async delById(id){
        return await this.model('news').where({_id:id}).delete();
    }
    async findById(id){
        return await this.model('news').where({_id:id}).find();
    }
    save(obj){
        let newsModel = this.model('news');
        if(obj._id){
            return newsModel.where({_id:obj._id}).update(obj);
        }else{
            obj['createTime'] = moment().format('YYYY-MM-DD hh:mm:ss');
            return newsModel.add(obj);
        }
    }
    async apiFind(type,limit){
        return this.model('news')
            .limit(limit||100)
            .order('createTime desc')
            .select();
    }
}